home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / grafik / bildanzeiger / superview-lib_dev / example_tools / simpleop / simpleop.c < prev    next >
C/C++ Source or Header  |  1995-03-09  |  9KB  |  296 lines

  1. /* ======================================================================== */
  2. /* = Programmname    : SimpleOP V9.1                      = */
  3. /* =                                      = */
  4. /* ======================================================================== */
  5. /* = Author/Copyright : (c) 1993-94 by Andreas Ralph Kleinert.            = */
  6. /* =               Freeware. All rights reserved.              = */
  7. /* =                                      = */
  8. /* =                   Use it as an example for programming               = */
  9. /* =                   superview.library !                                = */
  10. /* =                                      = */
  11. /* ======================================================================== */
  12. /* = Last Update      : 28.9.1994                      = */
  13. /* =                                      = */
  14. /* ======================================================================== */
  15. /* = Remarks          : Needs "asl.library" V37+                          = */
  16. /* =                and "superview.library" V9+.                      = */
  17. /* ======================================================================== */
  18. /* = Compiler          : SAS/C V6.51                        = */
  19. /* =                (smakefile)                                       = */
  20. /* ======================================================================== */
  21.  
  22. #include <exec/types.h>
  23. #include <exec/memory.h>
  24.  
  25. #include <intuition/intuitionbase.h> /* accessing IntuitionBase->FirstScreen */
  26.  
  27. #include <superview/superview.h>
  28. #include <superview/superviewbase.h>
  29.  
  30. #include <libraries/asl.h>
  31. #include <workbench/startup.h>
  32.  
  33. #include <proto/exec.h>
  34. #include <proto/dos.h>
  35. #include <proto/asl.h>
  36. #include <proto/superview.h>
  37. #include <proto/superviewsupport.h>
  38.  
  39. #include <stdio.h>
  40. #include <stdlib.h>
  41. #include <string.h>
  42.  
  43.  
  44.    /* Help- and Info- Texts */
  45.  
  46. char entry1_text  [] = "\2331;32;40mSimpleOP V9.1 \2330;32;40m\2333;32;40m(FREEWARE)\2330;32;40m\n(c) 1993-94 by Andreas Ralph Kleinert.\nAndreas R. Kleinert, Grube Hohe Grethe 23, D-57074 Siegen, Germany.\n";
  47. char entry2_text  [] = "Demonstrates SVOperator usage.\n";
  48. char entry3_text  [] = "USAGE : \2330;33;40mSimpleOP\2330;31;40m <PicFileName>\n";
  49.  
  50.  
  51. char ver_text [] = "\0$VER: SimpleOP V9.1 (28.9.94)";
  52.  
  53.  
  54. /* *************************************************** */
  55. /* *                             * */
  56. /* * Error-Messages for Leave() and KF_Message()     * */
  57. /* *                             * */
  58. /* *************************************************** */
  59.  
  60. char asllib_text     [] = "You need \42asl.library\42 V37+ !";
  61. char svlib_text     [] = "You need \42superview.library\42 V9+ !";
  62. char svsuplib_text      [] = "You need \42superviewsupport.library\42 V4+ !";
  63.  
  64.  
  65. /* *************************************************** */
  66. /* *                             * */
  67. /* * Function Declarations                 * */
  68. /* *                             * */
  69. /* *************************************************** */
  70.  
  71. void __regargs SimpleOP(char *filename);
  72.  
  73.  
  74. void __regargs Leave(char *endtext, long code);
  75.  
  76.  
  77.    /* Functions from module "SimpleOP_Subs.o" : */
  78.  
  79. extern void __stdargs K_Printf(char *formatstring, ...);
  80.  
  81.  
  82. /* *************************************************** */
  83. /* *                             * */
  84. /* * Additional Base Declarations             * */
  85. /* *                             * */
  86. /* *************************************************** */
  87.  
  88. extern struct ExecBase *SysBase;
  89.  
  90. struct Library       *AslBase       = N;
  91. struct SuperViewBase *SuperViewBase = N;
  92. struct SVSupportBase *SVSupportBase = N;
  93. struct IntuitionBase *IntuitionBase = N; /* Copied from SuperViewBase.  */
  94.                                          /* Do not close. Only used for */ 
  95.                                          /* accessing FrontScreen       */
  96.  
  97.  
  98. /* *************************************************** */
  99. /* *                             * */
  100. /* * MAIN                         * */
  101. /* *                             * */
  102. /* *************************************************** */
  103.  
  104. extern struct WBStartup *WBenchMsg;
  105. char                *wbloadname = N;
  106. long                     wb         = FALSE;
  107.  
  108. void main(long argc, char **argv)
  109. {
  110.  if(!argc)
  111.   {
  112.    wb = TRUE;
  113.  
  114.    if(WBenchMsg->sm_NumArgs>1) wbloadname = WBenchMsg->sm_ArgList[1].wa_Name;
  115.   }
  116.  
  117.  if( argc > 3 || (argv[1][0] =='?')||(argv[2][0] =='?'))
  118.   {
  119.    K_Printf("%s%s%s", entry1_text, entry2_text, entry3_text);
  120.  
  121.    Leave(N, 0);
  122.   }
  123.  
  124.  AslBase = (struct Library *) OpenLibrary("asl.library", 37);
  125.  if(!AslBase) Leave(asllib_text, 102);
  126.  
  127.  SuperViewBase = (struct SuperViewBase *) OpenLibrary("superview.library", 9);
  128.  if(!SuperViewBase) Leave(svlib_text, 103);
  129.  
  130.  SVSupportBase = (struct SVSupportBase *) OpenLibrary("superviewsupport.library", 4);
  131.  if(!SVSupportBase) Leave(svsuplib_text, 104);
  132.  
  133.  IntuitionBase = SuperViewBase->svb_IntuitionBase;
  134.  
  135.  /* ^ if NULL, sv-lib wouldn't have opened ! */
  136.  
  137.  
  138.  /* Show */
  139.  
  140.  if(argc < 2 && !wbloadname)
  141.   {
  142.    struct FileRequester     *request;
  143.    struct TagItem __aligned  tags[4];
  144.    char                      namebuffer [256];
  145.  
  146.    namebuffer[0] = (char) 0;
  147.  
  148.    tags[0].ti_Tag  = (Tag)   ASL_Hail;
  149.    tags[0].ti_Data = (ULONG) "Select Picture to Display :";
  150.  
  151.    tags[1].ti_Tag  = (Tag)   ASL_OKText;
  152.    tags[1].ti_Data = (ULONG) " Display ";
  153.  
  154.    tags[2].ti_Tag  = (Tag)   ASL_CancelText;
  155.    tags[2].ti_Data = (ULONG) " Quit ";
  156.  
  157.    tags[3].ti_Tag  = (Tag)   TAG_DONE;
  158.    tags[3].ti_Data = (ULONG) N;
  159.  
  160.    request = AllocAslRequest(ASL_FileRequest, N);
  161.    if(request)
  162.     {
  163.      if(AslRequest(request, &tags[0]))
  164.       {
  165.        strcpy(namebuffer, request->rf_Dir);
  166.        if(    (namebuffer[strlen(namebuffer)-1] !=      ':')
  167.            && (namebuffer[strlen(namebuffer)-1] !=      '/')
  168.            && (namebuffer[0]                    != (char) 0) ) strcat(namebuffer, "/");
  169.  
  170.        strcat(namebuffer, request->rf_File);
  171.  
  172.        if(namebuffer[0] != (char) 0) SimpleOP(namebuffer);
  173.       }
  174.  
  175.      FreeAslRequest(request);
  176.     }
  177.   }else
  178.   {
  179.    if(wbloadname) SimpleOP(wbloadname);
  180.     else SimpleOP(argv[1]);
  181.   }
  182.  
  183.  Leave(N, 0);
  184. }
  185.  
  186. /* *************************************************** */
  187. /* *                             * */
  188. /* * Operator-Function ( + Show)                     * */
  189. /* *                             * */
  190. /* *************************************************** */
  191.  
  192. void __regargs SimpleOP(char *filename)
  193. {
  194.  ULONG                       retval        = SVERR_NO_ERROR;
  195.  APTR                        handle        = N;
  196.  struct SVSUP_DisplayHandle *displayhandle = N;
  197.  APTR dummy;
  198.  
  199.  displayhandle = AllocVec(sizeof(struct SVSUP_DisplayHandle), MEMF_CLEAR|MEMF_PUBLIC);
  200.  if(displayhandle)
  201.   {
  202.    SVL_GetGlobalDriver(&displayhandle->SVDriverNode, N);
  203.  
  204.    handle = SVL_AllocHandle(N);
  205.    if(handle)
  206.     {
  207.      if(!(retval = SVL_InitHandleAsDOS(handle, N)))
  208.       {
  209.        displayhandle->WinIDCMP = IDCMP_MOUSEBUTTONS;
  210.        displayhandle->ScrType  = CUSTOMSCREEN;
  211.  
  212.                    retval = SVL_ReadToGfxBuffer(handle, filename);
  213.        if(!retval) retval = SVL_GetGfxBuffer(   handle, (APTR) &dummy, N);
  214.         {
  215.          APTR handle2;
  216.  
  217.          handle2 = SVL_AllocHandle(N);
  218.          if(handle2)
  219.           {
  220.            retval = SVL_DoOperation(handle2, (APTR) dummy, (APTR) &displayhandle->SVGfxBuffer, (APTR) SuperViewBase->svb_SVOperatorList.lh_Head, N);
  221.  
  222.            SVL_FreeHandle(handle2);
  223.           }else retval = SVERR_NO_HANDLE;
  224.         }
  225.  
  226.        if(!displayhandle->SVGfxBuffer) K_Printf("\nGottCha !\n");
  227.  
  228.        if(!retval && displayhandle->SVGfxBuffer)
  229.         {
  230.          retval = SVSUP_DisplayGfxBuffer(displayhandle);
  231.          if(!retval)
  232.           {
  233.            if(displayhandle->Window)
  234.             {
  235.              WaitPort(displayhandle->Window->UserPort);
  236.             }
  237.           }
  238.  
  239.          SVSUP_UnDisplayGfxBuffer(displayhandle);
  240.         }
  241.  
  242.  
  243.  
  244.  
  245.        if(!displayhandle->SVGfxBuffer) K_Printf("\nGottCha 2 !\n");
  246.  
  247.        if(!retval && displayhandle->SVGfxBuffer)
  248.         {
  249.          SVL_GetGlobalDriver(&displayhandle->SVDriverNode, N);
  250.          displayhandle->WinIDCMP = IDCMP_MOUSEBUTTONS;
  251.          displayhandle->ScrType  = CUSTOMSCREEN;
  252.  
  253.          retval = SVSUP_DisplayGfxBuffer(displayhandle);
  254.          if(!retval)
  255.           {
  256.            if(displayhandle->Window)
  257.             {
  258.              WaitPort(displayhandle->Window->UserPort);
  259.             }
  260.           }
  261.  
  262.          SVSUP_UnDisplayGfxBuffer(displayhandle);
  263.         }
  264.  
  265.  
  266.  
  267.       }
  268.  
  269.      SVL_FreeHandle(handle);
  270.  
  271.     }else retval = SVERR_NO_HANDLE;
  272.  
  273.    FreeVec(displayhandle);
  274.  
  275.   }else retval = SVERR_NO_MEMORY;
  276.  
  277.  if(retval) K_Printf("\n%s\n", SVL_GetErrorString(retval));
  278. }
  279.  
  280. /* *************************************************** */
  281. /* *                             * */
  282. /* * LEAVE : Global Exit Function Replacement         * */
  283. /* *                             * */
  284. /* *************************************************** */
  285.  
  286. void __regargs Leave(char *endtext, long code)
  287. {
  288.  if(SVSupportBase) CloseLibrary((APTR) SVSupportBase);
  289.  if(SuperViewBase) CloseLibrary((APTR) SuperViewBase);
  290.  if(AslBase)       CloseLibrary((APTR) AslBase);
  291.  
  292.  if(endtext)       if(!wb) K_Printf("%s\n", endtext);
  293.  
  294.  exit(code);
  295. }
  296.